package com.qx.frame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import com.qx.frame.panel.FunctionPanel;
import com.qx.frame.panel.InfoPanel;
import com.qx.util.SwingUtils;

/**
 * 描述：<br>
 * 主体窗口
 * 
 * @author LazyBear
 * @data 2014-4-16
 */
public class MainFrame extends JFrame {

	private static final long serialVersionUID = -1505224026116943333L;

	private static MainFrame instance;

	public static JFrame creatMainFrame() {
		if (instance == null)
			instance = new MainFrame();
		return instance;
	}

	private MainFrame() {
		initMenu(this);
		SwingUtils.initFrame(this);
		SwingUtils.setMidScree(this);
		this.add(FunctionPanel.getInstance());
		this.add(InfoPanel.getInfoPanel());
		this.setVisible(true);
	}

	/**
	 * 初始化菜单
	 * 
	 * @author LazyBear 描述:<br>
	 */
	private void initMenu(final JFrame frame) {
		JMenuBar jb = new JMenuBar();
		JMenu start = new JMenu();
		JMenuItem function = new JMenuItem();
		function.setText("功能测试");
		function.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				FunctionPanel.getInstance().setVisible(true);
				InfoPanel.getInfoPanel().setVisible(false);
				MainFrame.creatMainFrame().repaint();

			}
		});
		JMenuItem logging = new JMenuItem();
		logging.setText("日志查看");
		logging.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				FunctionPanel.getInstance().setVisible(false);
				InfoPanel.getInfoPanel().setVisible(true);
				MainFrame.creatMainFrame().repaint();
			}
		});
		start.setText("开始");
		start.add(function);
		start.add(logging);
		jb.add(start);
		frame.setJMenuBar(jb);
	}
}
